import uuid
from django.db import models

# 任务状态的枚举值
status = [
    (0, '就绪'),
    (1, '执行中'),
    (2, '完成'),
    (3, '失败'),
]


class Task(models.Model):
    class Meta:
        verbose_name = '语音识别任务'

    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    url = models.CharField(max_length=255, blank=True, null=True, verbose_name='文件网络路径')
    rel_path = models.CharField(max_length=255, blank=True, null=True, verbose_name='文件实际路径')
    status = models.IntegerField(choices=status, default=0, verbose_name='任务状态')
    res = models.JSONField(blank=True, null=True, verbose_name='识别结果-json')
    comment = models.TextField(blank=True, null=True, verbose_name='备注')
    idt = models.DateTimeField(auto_now_add=True)
    udt = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.res


class TaskRes(models.Model):
    class Meta:
        verbose_name = '语音识别任务结果'

    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    task = models.ForeignKey(Task, db_constraint=False, on_delete=models.CASCADE, blank=False, null=False, verbose_name='语音识别任务')
    res = models.JSONField(blank=True, null=True, verbose_name='识别结果-json')
    idt = models.DateTimeField(auto_now_add=True)
    udt = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.res